var app = angular.module('meetingApp.controllers');

app.controller('orderCtr', ['$rootScope', '$scope', 'ajaxService', 'toastPCService',
    function ($rootScope, $scope, ajax, toast) {


        $scope.data = {
            shop: [],
            list: [],
            pages: 1,
            count: 0,
            search: {
                page: 1,
                pageSize: 15,
                keyword: '',
                type: '',
                status: '',
                pay_status:''
            },
            edit: {}
        };
        $scope.export = function () {
            window.open('/admin/order/export?wx_id=' + $scope.data.search.wx_id + '&keyword=' + $scope.data.search.keyword + '&shop_id=' + $scope.data.search.shop_id + '&type='
                + $scope.data.search.type + "&stime=" + $scope.data.search.stime + '&etime=' + $scope.data.search.etime)
        }
        $scope.$on('$stateChangeSuccess', function () {

        })
        $scope.showIcCard = function (item){
            $scope.data.edit = angular.copy(item);
            $('#idcardModal').modal();
        }
        $scope.edit = function (item) {
            $scope.data.edit = angular.copy(item);
            $('#myModal').modal();
        }
        $scope.commit = function () {
            if ($('#editForm').valid()) {
                ajax('orderSave', $scope.data.edit, function (rel) {
                    if (!rel.errCode) {
                        toast.show(1, '保存成功');
                        $scope.getList();
                        $('#myModal').modal('hide');
                    }
                })
            }
        }
        $scope.del = function (item) {
            layer.confirm('确定删除?', ['确定', '取消'], function () {
                ajax('orderDel', {id: item.id}, function (rel) {
                    if (!rel.errCode) {
                        layer.closeAll()
                        toast.show(1, '删除成功');
                        $scope.getList();
                    }
                })
            })
        }
        $scope.success = function (item) {
            layer.confirm('确定交易成功了吗?', ['确定', '取消'], function () {
                ajax('orderSuccess', {id: item.id}, function (rel) {
                    if (!rel.errCode) {
                        layer.closeAll()
                        toast.show(1, '操作成功');
                        $scope.getList();
                    }
                })
            })
        }
        $scope.error = function (item) {
            layer.confirm('确定交易失败了吗?', ['确定', '取消'], function () {
                ajax('orderError', {id: item.id}, function (rel) {
                    if (!rel.errCode) {
                        layer.closeAll()
                        toast.show(1, '操作成功');
                        $scope.getList();
                    }
                })
            })
        }
        $scope.getList = function (page) {
            if (page) {
                $scope.data.search.page = page;
            }
            ajax('orderIndex', $scope.data.search, function (rel) {
                if (!rel.errCode) {
                    $scope.data.list = rel.data.data;
                    $scope.data.pages = rel.data.last_page;
                    $scope.data.count = rel.data.total;
                }
            })
        }
    }
])